SUBROUTINE readmech
	
	USE ckvar

	IMPLICIT NONE
	INTEGER :: io,i,j,k
	CHARACTER(8) :: tzz,txx(4)

	
	io=0
	i=0
	j=0
	k=0
	nelm=0	!! # of elements in read
	nspc=0	!! # of species in read
	nreac=0	!! # of reactions
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! READ ELEMENTS from mech.dat & open the file !!
!! This routine will give 'nelm' and assign   !!
!! elements to the variable elm(i)            !!
	open(unit=10,file='UCSD/mech.dat')
	DO
	IF(io.ne.0) THEN
!	write(*,*) 'end of file'
	EXIT
	ENDIF
	read(10,*,IOSTAT=io) tzz
	if(tzz.eq.'ELEMENTS') then
	read(10,*,IOSTAT=io) (elm(j),j=1,10)
	DO i=1,10
	if(elm(i).eq.'END') then
	nelm=i-1
!	write(*,*) '# of elements:',nelm
!	write(*,*) (elm(j),j=1,nelm)
	endif
	if(nelm.gt.0) EXIT
	ENDDO	
	EXIT
	endif
	ENDDO	
	close(10)	
!! End of reading ELEMENTS from mech.dat       !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

	io=0
	i=0
	j=0
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! READ SPECIES from mech.dat & reopen the file !!
	open(unit=10,file='UCSD/mech.dat')
	DO
	IF(io.ne.0) THEN
!	write(*,*) 'end of file'
	EXIT
	ENDIF
	read(10,*,IOSTAT=io) tzz
	if(tzz.eq.'SPECIES') then
	read(10,*,IOSTAT=io) (spc(j),j=1,mxspc)
	DO i=1,100
	if(spc(i).eq.'END') then
	nspc=i-1
!	write(*,*) '# of species:',nspc
!	write(*,100) (spc(j),j=1,nspc)
	endif
	if(nspc.gt.0) EXIT
	ENDDO
	endif
	ENDDO
	close(10)
!! End of reading SPECIES from mech.dat         !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
	io=0
	i=0
	j=0
	ispreac=0.0
	nspreac=0.0
!! READ reactions from mech.dat
	open(unit=10,file='UCSD/mech.dat')
	DO
	IF(io.ne.0) EXIT
	read(10,*,IOSTAT=io) tzz
	if(tzz.eq.'REACTION') then
	DO i=1, 100
	read(10,*,IOSTAT=io) (txx(j),j=1,4)
	do j=1,4
	  do k=1,nspc
	  if(txx(j).eq.spc(k)) ispreac(i,j)=k
	  enddo
	enddo
	read(10,*,IOSTAT=io) (nspreac(i,j),j=1,4)
	if(io.ne.0) exit
	nreac=i
	ENDDO
	endif
	ENDDO
	close(10)
!	write(*,*) 'nreac',nreac
!	do i=1,nreac
!	write(*,*) (spc(ispreac(i,j)),j=1,3)
!	write(*,*) (nspreac(i,j),j=1,3)
!	enddo
  100	format(a8,2x)
END SUBROUTINE readmech
